package com.wgworkshop.pems.entity.converter;

import com.wgworkshop.pems.common.enums.StudentStatusEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * 学生状态转换器。
 * Created by wlc on 2017/7/2.
 */
@Converter
public class StudentStatusConverter implements AttributeConverter<StudentStatusEnum, Integer> {

    @Override
    public Integer convertToDatabaseColumn(StudentStatusEnum attribute) {
        if (attribute == null) {
            return null;
        }
        return attribute.getCode();
    }

    @Override
    public StudentStatusEnum convertToEntityAttribute(Integer dbData) {
        if (dbData == null) {
            return null;
        }
        return StudentStatusEnum.fromCode(dbData);
    }
}
